package com.cangjie.xiaozhi

import com.intellij.openapi.components.Service

@Service
class XiaozhiToolWindowService {
    private var toolWindow: XiaozhiToolWindow? = null
    
    fun setToolWindow(toolWindow: XiaozhiToolWindow) {
        this.toolWindow = toolWindow
        println("ToolWindow已设置")
    }
    
    fun getToolWindow(): XiaozhiToolWindow? {
        println("获取ToolWindow实例: ${toolWindow != null}")
        return toolWindow
    }
    
    fun sendMessageToXiaoZhi(message: String) {
        println("通过服务发送消息: $message")
        toolWindow?.sendMessageToEditor(message) ?: println("ToolWindow为空，无法发送消息")
    }
    
    companion object {
        fun getInstance(): XiaozhiToolWindowService {
            val instance = com.intellij.openapi.components.ServiceManager.getService(XiaozhiToolWindowService::class.java)
            println("获取XiaozhiToolWindowService实例: ${instance != null}")
            return instance
        }
    }
}